package com.richardjaap.jersey;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.richardjaap.data.Bet;
import com.richardjaap.data.Lobby;
import com.richardjaap.data.Player;
import com.richardjaap.data.RouletteTable;


@Path("/table")
public class RouletteTableResource {
	
	@GET
	@Path("{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public RouletteTable table(@PathParam("id") int id)
	{
		return Lobby.getInstance().getTable(id);
	}
	
	@POST
	@Path("{id}")
	@Consumes(MediaType.APPLICATION_JSON)
	public RouletteTable bet(Bet bet, @PathParam("id") int id)
	{
		Player p = Lobby.getInstance().getPlayer(bet.getPlayerId());
		if(p == null)
			return null;
		p.bet(bet);
		return p.getCurrentTable();
	}
}
